package com.longxi.tianjintianbao.ui.presenter.goodstraffic;

import android.view.View;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.GoodsTrafficListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.goodstraffic.GoodsTrafficListFragment;
import com.longxi.tianjintianbao.ui.view.goodstraffic.IGoodsTrafficListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class GoodsTrafficListAtPresenter extends BasePresenter<IGoodsTrafficListAtView> {

    private GoodsTrafficListPagerAdapter goodsTrafficListPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未离开");
        mCategoryList.add("已离开");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public GoodsTrafficListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTitle("物品放行");
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        mContext.setTvRight("登记");
        mContext.mTvRight.setVisibility(View.VISIBLE);
        initVariable();
    }

    public void initViewPager(){
        goodsTrafficListPagerAdapter = new GoodsTrafficListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList());
        getView().getViewPager().setAdapter(goodsTrafficListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        GoodsTrafficListFragment goodsTrafficListFragment = (GoodsTrafficListFragment) goodsTrafficListPagerAdapter.getCurrentFragment();
        goodsTrafficListFragment.refreshReceiptList();
    }

}
